
/**
 * 表示 站点上 所属线路编码
 */
Subwaymap.StationCode = org.gridsofts.util.Class.define({
    name: "Subwaymap.StationCode",

    /**
     * 构造函数
     */
    construct: function (container, line, station, group) {
        if (arguments.length == 0 || typeof (arguments[0]) != "object") {
            throw new Error("Object construct parameter is empty, unable to initialize instance of Station.");
        }

        this.container = container;
        this.line = line;
        this.station = station;
        this.group = group;

        this.color = "#" + (line?.color && line?.color.length > 0 ? line.color : 0x0);
        this.text = parseInt(parseInt(line.code));
        this.repaint();
    },

    /**
     * 方法
     */
    methods: {
        repaint: function () {
            this.actualDrawStation();
        },

        /** 
         * 调用绘图API，在画布上绘制图元
         */
        actualDrawStation: function () {
            var routeMapStopID = this.station.routeMapStopID;
            var subStation = this.station;
            var line = this.line;

            var text;
            if (this.station.virtualStop) {
                text = new Kinetic.Image({
                    x: this.station.stopX,
                    y: this.station.stopY,
                    image: "../images/InactiveStation.png",
                    width: 45,
                    height: 45,
                });
            }
            else {
                text = new Kinetic.Text({
                    x: this.station.stopX,
                    y: this.station.stopY,
                    fontVariant: 'small-caps',
                    //text: this.text,
                    align: 'center',
                    fontSize: 28,
                    fontFamily: 'Arial',
                    fill: this.color,
                });
            }

            var width = text.width();
            var heigth = text.height();
            text.y(text.y() - heigth / 2); //上下居中
            text.x(text.x() - width / 2);  //左右居中

            this.group.add(text);

            this.group.addEventListener("click", function () {
                return false;
            });

            this.container.add(this.group);
        },
    }
});